﻿using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Xml.Serialization;
using Landpy.CruiseControlNet.Infrastructure.Control;

namespace Landpy.CruiseControlNet.FacadeInterface.ConfigurationModule
{
    public class SourceControl : IPrimaryKey
    {
        [Browsable(false)]
        [XmlIgnore]
        public Guid Id { get; private set; }

        #region Common

        [Category("Basic")]
        [Description("The type of sourcecontrol.")]
        [XmlAttribute("type")]
        public SourceControlType Type { get; set; }

        [Category("Basic")]
        [Description("Username that should be used. Domain cannot be placed here, rather in domain property.")]
        [XmlElement("username")]
        public string UserName { get; set; }

        [Category("Basic")]
        [Description("The password in clear text of the domain user to be used.")]
        [XmlElement("password")]
        public string Password { get; set; }

        #endregion

        #region VSTS

        [Category("Basic")]
        [Description("The name or URL of the team foundation server. For example http://vstsb2:8080 or vstsb2 if it has already been registered on the machine.")]
        [XmlElement("server")]
        public string Server { get; set; }

        [Category("Basic")]
        [Description(@"The path to the project in source control, for example $\VSTSPlugins")]
        [XmlElement("project")]
        public string Project { get; set; }

        [Category("Basic")]
        [Description("The domain of the user to be used.")]
        [XmlElement("domain")]
        public string Domain { get; set; }

        [Category("Basic")]
        [Description("The working directory to use.")]
        [XmlElement("workingDirectory")]
        [Editor(typeof(FileLocationEditor), typeof(UITypeEditor))]
        public string WorkingDirectory { get; set; }

        [Category("Basic")]
        [Description("Flag indicating if workspace should be deleted every time or if it should be left (the default). Leaving the workspace will mean that subsequent gets will only need to transfer the modified files, improving performance considerably.")]
        [XmlElement("deleteWorkspace")]
        public string DeleteWorkspace { get; set; }

        [Category("Basic")]
        [Description("Whether to automatically get the source.")]
        [XmlElement("autoGetSource")]
        public string AutoGetSource { get; set; }

        [Category("Basic")]
        [Description("Whether to do a clean copy.")]
        [XmlElement("cleanCopy")]
        public string CleanCopy { get; set; }

        [Category("Basic")]
        [Description("Encoding Code page to use for communicating with TFS, Empty String, will default to UTF-8 encoding. " +
                     "Note: Encoding for simplified Chinese 936 will resolve Chinese langurage CruiseControl.NET String was not recognized as a valid DateTime（VstsHistoryParser.ParseChangeSet）issue.")]
        [XmlElement("codepage")]
        public int? Codepage { get; set; }

        [XmlIgnore]
        [Browsable(false)]
        public bool CodepageSpecified { get { return this.Codepage != null; } }

        [Category("Basic")]
        [Description("Name of the workspace to create. This will revert to the DEFAULT_WORKSPACE_NAME if not passed.")]
        [XmlElement("workspace")]
        public string Workspace { get; set; }

        #endregion

        #region SVN

        [Category("Basic")]
        [Description("The url for your repository (e.g., svn://svnserver/).")]
        [XmlElement("trunkUrl")]
        public string TrunkUrl { get; set; }

        [Category("Basic")]
        [Description("The location of the svn executable.")]
        [XmlElement("executable")]
        public string Executable { get; set; }

        #endregion

        public SourceControl()
        {
            this.Type = SourceControlType.VSTS;
            this.Id = Guid.NewGuid();
        }
    }
}